//
//  FWMeController.m
//  BirdLoveSheep
//
//  Created by wwj on 16/3/8.
//  Copyright © 2016年 wwj. All rights reserved.
//

#import "FWMeController.h"
#import "UIBarButtonItem+Extension.h"
#import "FWTopWindownController.h"
#import "FWMeCell.h"
#import "FWMeHeaderView.h"
#import "FWMeFooterView.h"
#import "FWMeWebController.h"

@interface FWMeController ()
@property (weak, nonatomic) FWMeFooterView *footerView;
@property (assign, nonatomic) CGSize contentSize;
@end

@implementation FWMeController

static NSString *ID = @"FWMeCell";
static NSString *HeadID = @"FWMeHeaderView";

- (void)viewDidLoad{
    [super viewDidLoad];
    
    [self setup];
}

- (void)setup{
    self.view.backgroundColor = kBgColor;
    self.navigationItem.title = @"我的";
    
    UIBarButtonItem *settingBtn = [UIBarButtonItem fw_itemWithIcon:@"mine-setting-icon" highIcon:@"mine-setting-icon-click" target:self action:@selector(onClickSetting)];
    UIBarButtonItem *moonBtn = [UIBarButtonItem fw_itemWithIcon:@"mine-moon-icon" highIcon:@"mine-moon-icon-click" target:self action:@selector(onClickChang)];
    
    self.navigationItem.rightBarButtonItems = @[settingBtn, moonBtn];
    
    [self.tableView registerClass:[FWMeCell class] forCellReuseIdentifier:ID];
    
    self.tableView.tableHeaderView = [FWMeHeaderView headerView];
    FWMeFooterView *footerView = [FWMeFooterView footerView];
    self.tableView.tableFooterView = footerView;
    self.footerView = footerView;
    
    self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
    self.tableView.sectionFooterHeight = 10;
    
    self.footerView.block = ^(FWSquareModel *model){
        FWMeWebController *webVC = [[FWMeWebController alloc] init];
        MyLog(@"%@", model.url);
        if ([model.url hasPrefix:@"http"] || [model.url hasPrefix:@"https"]) {
            webVC.url = model.url;
            webVC.title = model.name;
            [self.navigationController pushViewController:webVC animated:YES];
        }
    };
}

- (void)onClickSetting{
    [self.tableView reloadData];
}

- (void)onClickChang{
    MyLog(@"%s", __func__);
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FWMeCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (indexPath.row == 0) {
        cell.imageView.image = [UIImage imageNamed:@"mine_icon_random"];
        cell.textLabel.text = @"我的身份";
    }else if (indexPath.row == 1){
        cell.imageView.image = [UIImage imageNamed:@"mine-icon-manhua"];
        cell.textLabel.text = @"离线下载";
    }
    return cell;
}

@end
